/*
 * @Description:
 * @Author: Mr.Wen
 * @Version: v1.0.0
 * @Date: 2022-07-22 22:37:11
 * @LastEditors: Mr.Wen - 文先生
 * @LastEditTime: 2022-08-23 10:21:40
 */
const xlsx = require('node-xlsx');
const fs = require('fs');

let xlsx_path = './2018年6月计算机水平考试成绩.xls';
let xlsx_data = xlsx.parse(xlsx_path);

// eslint-disable-next-line
xlsx_data.forEach((sheet, index) => {
  // console.log(sheet);
  // console.log("表格名称", sheet.name);
  // console.log("表格数据", sheet.data);
  // console.log("表头信息", sheet.data[1]);
  // console.log("真正的数据内容", sheet.data.slice(1));

  let computer_test_scoress = [];

  // 将表中的内容提取出来，写入JSON文件中
  // eslint-disable-next-line
  sheet.data.slice(2).forEach((e, i) => {
    let json = {
      admitNumber: e[0],
      name: e[1],
      sex: e[2],
      studentID: e[3],
      idNumber: e[4],
      class: e[5],
      tie: e[6],
      testName: e[7],
      languageName: e[8],
      results: e[9],
      overall: e[10],
      authorizedNumber: e[11],
    };
    computer_test_scoress.push(json);
  });

  fs.writeFile(
    './computer_scores.json',
    JSON.stringify(computer_test_scoress, null, 2),
    (err) => {
      if (err) {
        console.log('写入失败', err);
      } else {
        console.log('写入成功');
      }
    }
  );
});
